//==========================================================================//
//                                                                          //
//  ZXTHERM Library             Version 0.1                     March 2012  //
//                                                                          //
//  Written for the Arduino Duemilanove w/ ATmega328                        //
//                                                                          //
//  ZXTHERM Arduino Library                                                 //
//                                                                          //
//  Created by JFLagarde (jeanfrancoislagarde@hotmail.com)                  //
//                                                                          //
//  This file is part of OpenWS (http://code.google.com/p/openws/)          //
//                                                                          //
//==========================================================================//
//                                                                          //
//  Notes:                                                                  //
//                                                                          //
//                                                                          //
//==========================================================================//
//                                                                          //
//  Copyright 2012 Jean-Francois Lagarde (jeanfrancoislagarde@hotmail.com)  //
//  This program is distributed under the terms of                          //
//  the GNU General Public License                                          //
//                                                                          //
//  This program is free software: you can redistribute it and/or modify    //
//  it under the terms of the GNU General Public License as published by    //
//  the Free Software Foundation, either version 3 of the License, or       //
//  (at your option) any later version.                                     //
//                                                                          //
//  This program is distributed in the hope that it will be useful,         //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//  GNU General Public License for more details.                            //
//                                                                          //
//  You should have received a copy of the GNU General Public License       //
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                          //
//==========================================================================//

#include <ZXTHERM.h>

ZXTHERM::ZXTHERM() {
	_pin = 0;		
    _lastTemperature = 0;
}

void ZXTHERM::init() {
	init(0);
}
void ZXTHERM::init(int pin) {
	_pin = pin;
	}
void ZXTHERM::read() {
	_lastTemperature = readTemperature();
}
int ZXTHERM::getTemperature() {
	return _lastTemperature;
}














//PRIVATE methods
int ZXTHERM::readTemperature(){
	int val = analogRead(_pin);
	val = val/1.06667 -164.062;

	return val;
}


/*
http://pastebin.com/rhsuDUD4
float convertToCelsius(int valueread) {
    if(valueread<340) {
    return -5.0 + (valueread-120.0)/(340-120) * ( 15.0 + 5.0 ) + 3.5;
  } else if(valueread<500) {
    return 15.0 + (valueread-340.0)/(500-340) * (30 - 15.0) + 3.5;
  } else if(valueread<660) {
    return 30.0 + (valueread -500.0) /(660-500) * (50 - 30) + 3.5;
  } else {
    return 50.0 + (valueread-660.0) /(790 - 660) * (75 - 50) + 3.5;
  }
}
*/